package com.fenxiangtech.mall.web.controller.v1;

import com.fenxiangtech.mall.entity.Order;
import com.fenxiangtech.mall.entity.OrderProduct;
import com.fenxiangtech.mall.service.OrderService;
import com.fenxiangtech.mall.dto.PageData;
import com.fenxiangtech.mall.dto.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhangjiashun
 */
@Controller("orderControllerV1")
@RequestMapping("/v1/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping
    @ResponseBody
    public Result placeOrder(@RequestBody List<OrderProduct> orderProducts) {
        return orderService.place(orderProducts);
    }

    @GetMapping("/by_user")
    @ResponseBody
    public PageData<Order> getOrderByUser(Integer page, Integer size) {
        return orderService.getOrderByUser(page, size);
    }

    @GetMapping("/{id}")
    @ResponseBody
    public Order getOrderByID(@PathVariable("id") Long id) {
        Order order = orderService.getOrderByID(id);
        return order;
    }

    @GetMapping("/list")
    @ResponseBody
    public PageData<Order> listOrder(Integer page, Integer size) {
        return orderService.listOrder(page, size);
    }

    @PutMapping(value = "/delivery/{id}")
    @ResponseBody
    public Result<Order> delivery(@PathVariable("id") Long id) {
        return orderService.delivery(id);
    }

}
